from django.db import models
from utils.models import CoreModel
from django.contrib.auth.models import AbstractUser
# Create your models here.

# 集成所有的CoreModel
class Demo(CoreModel):
    name = models.CharField(max_length=255, blank=True, null=True, verbose_name='姓名')
    age = models.IntegerField(blank=True, null=True, verbose_name='年龄')
    class Meta:
        db_table = "demo"
        verbose_name = 'demo模型'
        verbose_name_plural = verbose_name
        
class Users(CoreModel, AbstractUser):
    email = models.EmailField(max_length=255, verbose_name="邮箱", null=True, blank=True, help_text="邮箱")
    mobile = models.CharField(max_length=255, verbose_name="电话", null=True, blank=True, help_text="电话")
    avatar = models.CharField(max_length=255, verbose_name="头像", null=True, blank=True, help_text="头像")
    name = models.CharField(max_length=40, verbose_name="姓名", help_text="姓名")
    GENDER_CHOICES = (
        (0, "未知"),
        (1, "男"),
        (2, "女"),
    )
    gender = models.IntegerField(
        choices=GENDER_CHOICES, default=0, verbose_name="性别", null=True, blank=True, help_text="性别"
    )

    def set_password(self, raw_password):
        super().set_password(hashlib.md5(raw_password.encode(encoding="UTF-8")).hexdigest())

    class Meta:
        db_table = "system_users"
        verbose_name = "用户表"
        verbose_name_plural = verbose_name
        ordering = ("-create_datetime",)
